<!-- echarts饼图组件 -->
<template>
  <div :ref="`pie${id}`" style="width: 100%; height: 30vh"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'PieChart',
  components: {},
  props: {
    id: {
      type: Number,
      default: 1,
    },
    title: {
      type: String,
      default: '标题',
    },
    bar: {
      type: Array,
      default: () => [],
    },
    arr: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {}
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.getAnnular()
  },
  methods: {
    resizeChart() {
      if (this.chart) {
        this.chart.resize()
      }
    },
    getAnnular() {
      var chartDom = this.$refs[`pie${this.id}`]
      var myChart = echarts.init(chartDom)
      var option

      option = {
        title: {
          text: this.title,
          y: 'bottom',
          x: 'center',
        },
        tooltip: {
          trigger: 'item',
        },
        legend: {
          orient: 'vertical',
          left: 'left',
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: [
              { value: 1048, name: '盒数' },
              { value: 735, name: '件数' },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)',
              },
            },
          },
        ],
      }

      option && myChart.setOption(option)
    },
  },
}
</script>
<style lang="less" scoped></style>
